package edu.columbia.aicheckers.agent.dummy;

import java.util.Iterator;
import java.util.Random;
import java.util.Set;

import edu.columbia.aicheckers.agent.IAgent;
import edu.columbia.aicheckers.model.Color;
import edu.columbia.aicheckers.model.IBoardState;
import edu.columbia.aicheckers.model.Move;

/**
 * Dumb agent that picks random moves
 * @author cttsao
 *
 */
public class DummyAgent implements IAgent
{
	Random rand = new Random();
	public Move doPly(IBoardState board,Color myColor)
	{
		Set<Move> moves = board.getAvailableMoves(myColor);
		if(!moves.isEmpty())
		{
			int picked = rand.nextInt(moves.size());
			int count = 0;
			Move m = null;
			Iterator<Move> movesIterator = moves.iterator();
			while(movesIterator.hasNext())
			{
				m = movesIterator.next();
				if(picked == count)
				{
					return m;
				}
				count++;
			}
			if(m == null)
			{
				throw new IllegalArgumentException("Move cannot be null - there must be something available");
			}
			return m;
		}
		else
		{
			return null;
		}
	}
}
